/*
 * NumericTolerances.java
 */

package complexchaos;

import java.lang.Object;
import java.util.*;

/**
 * I really have no idea what this one does. Don, care to explain?
 *
 * @author Don Spickler
 */
public class NumericTolerances implements Cloneable
{
	private boolean useZeroTol;
	private int ZeroExp;
	private double ZeroTol;
	private boolean useEqualityTol;
	private int EqualityExp;
	private double EqualityTol;

	public NumericTolerances() 
	{	
		useZeroTol = true;
		ZeroExp = -8;
		ZeroTol = Math.pow(10, ZeroExp);
		useEqualityTol = true;
		EqualityExp = -8;
		EqualityTol = Math.pow(10, EqualityExp);
	}

	public static NumericTolerances setForExactNumber()
	{
		NumericTolerances retval = new NumericTolerances();
		retval.setUseZeroTolerance(false);
		retval.setUseEqualityTolerance(false);
		
		return retval;
	}

	public int getZeroToleranceExponent()
	{
		return ZeroExp;
	}

	public int getEqualityToleranceExponent()
	{
		return EqualityExp;
	}

	public double getZeroTolerance()
	{
		return ZeroTol;
	}

	public double getEqualityTolerance()
	{
		return EqualityTol;
	}
	
	public boolean getUseZeroTolerance()
	{
		return useZeroTol;
	}

	public boolean getUseEqualityTolerance()
	{
		return useEqualityTol;
	}

	public void setZeroToleranceExponent(int exponent)
	{
		if (exponent < -1)
		{
			ZeroExp = exponent;
			ZeroTol = Math.pow(10.0, (double)ZeroExp);
		}
	}

	public void setEqualityToleranceExponent(int exponent)
	{
		if (exponent < -1)
		{
			EqualityExp = exponent;
			EqualityTol = Math.pow(10.0, (double)EqualityExp);
		}
	}

	public void setUseZeroTolerance(boolean b)
	{
		useZeroTol = b;
	}

	public void setUseEqualityTolerance(boolean b)
	{
		useEqualityTol = b;
	}

	public NumericTolerances clone()
	{
		NumericTolerances retval = new NumericTolerances();
		
		retval.useZeroTol = useZeroTol;
		retval.ZeroExp = ZeroExp;
		retval.ZeroTol = ZeroTol;
		retval.useEqualityTol = useEqualityTol;
		retval.EqualityExp = EqualityExp;
		retval.EqualityTol = EqualityTol;
		
		return retval;
	}


}
